<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content=" width=device-width,initial-scale=1.0">
        <link rel="stylesheet" href="css/common.css">
        <link rel="stylesheet" href="css/resign.css">
        <script src="js/jquery.min.js"></script>
        <title>注册页面</title>
    </head>
    <body>
        <div class="网页聊天室"></div>
        <div class="resign-container">
            <div class="resign-dialog">
                <h3>注册</h3>
                <div class="row">
                    <span>用户名：</span>
                    <input type="text" id="username">
                </div>
                <div class="row">
                    <span>密码：</span>
                    <input type="password" id="password">
                </div>
                <div class="row">
                    <span>确认密码：</span>
                    <input type="password" id="password2">
                </div>
                <div class="row">
                    <button id="submit" onclick="mysub()">注册</button>
                  </div>
            </div>
        </div>
      <script>
        function mysub(){
            var username=jQuery("#username");
            var password=jQuery("#password");
            var password2=jQuery("#password2");
            if(username==null||username.val().trim()==""){
                alert("用户名不能为空");
                username.focus();
                return false;
            }
            if(password==null||password.val().trim()==""){
                alert("密码不能为空");
                password.focus();
                return false;
            }
            if(password2==null||password2.val().trim()==""){
                alert("确认密码不能为空");
                password2.focus();
                return false;
            }
            if(password2.val()!=password.val()){
               alert("确认密码与密码不一致，请重新输入");
               password2.clearQueue();
               return false;
            }
            //根后端传输数据
            jQuery.ajax({
                url:"chatRoom/resign",
                type:"post",
                data:{
                    "username":username.val().trim(),
                    "password":password.val().trim()
                },
                success:function(res){
                    if(res.code==-1||res.data<=0){
                        alert("注册失败，请重试");
                        return;
                    }
                    if(res.code==1||res.data>0){
                        alert("注册成功");
                        location.href="login.html";
                        return;
                    }
                }

            });
        }
      </script>
    </body>
    </html>